import Loader from "./Loader"
import cjs=createjs
import Global from "./Global"
import GameControl from "./control/GameControl"
import { ViewEvent } from "./Const"
import DrawDebugRectEvent from "./events/DrawDebugRectEvent"
//import createjs from "../createjs"
//@ts-ignore
window.createjs=cjs
window.AdobeAn={}
//require('./ScaleBitmap.js')
require('./wxgame.js')
let stage:cjs.Stage
const {windowWidth,windowHeight} = wx.getWindowInfo()
console.log(windowWidth,windowHeight)
const stageWidth=750
const ri=windowWidth/stageWidth
const stageHeight=windowHeight/ri

Global.stageWidth=stageWidth
Global.stageHeight=stageHeight
Global.scale=ri

const loader=new Loader()
let aniId=0
const MainEntry=(canvas:HTMLCanvasElement | string | Object):void=>{
    Global.comp=window.AdobeAn.getComposition('21F88DEE3BA4504D95EDB59DC9A82C68')
    const exportRoot=new cjs.Container()
    stage=new cjs.Stage(canvas)
    //stage.scaleX=stage.scaleY=ri
    stage.setTransform(0,0,ri,ri)
    stage.addChild(exportRoot)
    //
    const debug=new cjs.Shape()
    stage.addChild(debug)
    exportRoot.on(ViewEvent.DRAW_DEBUG,(e:cjs.Event)=>{
        const evt=e as DrawDebugRectEvent
        const rect=evt.getRect()
        const g=debug.graphics
        g.clear()
        g.beginStroke('red')
        g.drawRect(rect.x,rect.y,rect.width,rect.height)
        g.endStroke()
    })
    GameControl.getInstance().init(exportRoot)
    cjs.Ticker.framerate=60
    cjs.Ticker.addEventListener("tick", ():void=>{
        stage.update()
    })
}
// 实现游戏帧循环
const loop=()=>{
    stage.update()
    aniId = window.requestAnimationFrame(
        loop
    )
  }
window.MainEntry=MainEntry